
const request = require('../../../utils/request');

Page({
    data:{
        userId: wx.getStorageSync('userId'),
        userHeaderUrl: '',
        userName: '',
        shareUserId: 0,
        isMy: false,     //是否是本人
        isNew: false,    //是否是新用户
        isOld: false,    //是否是老用户
        showGzh: false,  //是否展示关注公众号
    },

    onLoad(e) {
        console.log(e)
        console.log('userid:',this.data.userId)
        this.setData({
            shareUserId: e.userId
        })
        //判断是否是自己
        if(this.data.userId != ''){
            if(this.data.userId == e.userId){
                this.setData({
                    isMy: true,
                    isNew: false
                })
            }else{
                this.setData({
                    isOld: true,
                    isNew: false
                })
            }
        }else{
            this.setData({
                isNew: true
            })
        }

        //是否展示关注公众号
        var scene = ['1011', '1047', '1089', '1038'];
        var indexof = scene.indexOf(e.scene);
        console.log(indexof,e)
        if (indexof == -1) {
            //场景不在数组中的处理
            
        } else {
            //场景在数组中的处理
            console.log(11111)
            this.setData({
                showGzh: true
            })
        }

        //获取本地存储头像，名字
        let that = this
        wx.getStorage({
            key: 'user',
            success: function(res){
                console.log(res)
                that.setData({
                    userHeaderUrl: res.data.userHeaderUrl,
                    userName: res.data.userName,
                })
            }
        })
        
    },

    onShow() {
        //判断是否是自己
        let userId = wx.getStorageSync('userId');
        if(userId != ''){
            if(userId == this.data.shareUserId){
                this.setData({
                    isMy: true,
                    isNew: false
                })
            }else{
                this.setData({
                    isOld: true,
                    isNew: false
                })
            }
        }else{
            this.setData({
                isNew: true
            })
        }

        //获取本地存储头像，名字
        let that = this
        wx.getStorage({
            key: 'user',
            success: function(res){
                that.setData({
                    userHeaderUrl: res.data.userHeaderUrl,
                    userName: res.data.userName
                })
            }
        })

    },

    //登录
    login() {
        wx.navigateTo({
            url: '../../../pages/my/myLogin/myLogin?userId='+ this.data.shareUserId
        })
    },
    //返回首页
    goIndex() {
        wx.switchTab({
            url: '../../../pages/index/index'
        })
    }
})